package l2ft.gameserver.handler.admincommands.impl;

import java.util.ArrayList;
import java.util.List;

import l2ft.commons.util.Rnd;
import l2ft.gameserver.ai.MainFakePc;
import l2ft.gameserver.handler.admincommands.IAdminCommandHandler;
import l2ft.gameserver.instancemanager.FakePcFactory;
import l2ft.gameserver.model.Player;
import l2ft.gameserver.model.entity.Reflection;
import l2ft.gameserver.model.instances.FakePcInstance;
import l2ft.gameserver.utils.Location;

public class AdminFakePcs implements IAdminCommandHandler
{
	private static enum Commands
	{
		admin_fakearcher,
		admin_fakemage,
		admin_fakebishop,
		admin_faketank,
		admin_fakefighter,
		admin_faketeam,
		admin_startfight
	}

	private static List<FakePcInstance> _fakePcs = new ArrayList<FakePcInstance>();
	private static final int[] _fighters = {93, 101, 108, 117, 114, 113};
	@Override
	public boolean useAdminCommand(Enum comm, String[] wordList, String fullString, Player activeChar)
	{
		Commands command = (Commands) comm;
		System.out.println("command:"+command);
		Location loc = activeChar.getLoc();
		Reflection ref = activeChar.getReflection();
		switch(command)
		{
			case admin_fakearcher:
				spawnFakePc(Rnd.get(FakePcFactory.archers), loc, ref);
				break;
			case admin_fakemage:
				spawnFakePc(Rnd.get(FakePcFactory.mages), loc, ref);
				break;
			case admin_fakebishop:
				spawnFakePc(FakePcFactory.bishop, loc, ref);
				break;
			case admin_faketank:
				spawnFakePc(Rnd.get(FakePcFactory.tanks), loc, ref);
				break;
			case admin_fakefighter:
				spawnFakePc(Rnd.get(_fighters), loc, ref);
				break;
			case admin_faketeam:
				if(activeChar.getTarget() != null && activeChar.getTarget() instanceof FakePcInstance)
				{
					FakePcInstance target = (FakePcInstance) activeChar.getTarget();
					int team = Integer.parseInt(wordList[1]);
					target.setTeam(team);
					target.getAI().setTeam(team);
				}
				break;
			case admin_startfight:
				for(FakePcInstance fakePc : _fakePcs)
					((MainFakePc)fakePc.getAI()).startAI();
				break;
		}
		return true;
	}

	private void spawnFakePc(int clazz, Location loc, Reflection ref)
	{
		_fakePcs.add(FakePcFactory.newFakePc(clazz, false, loc, ref));
	}
	
	@Override
	public Enum[] getAdminCommandEnum()
	{
		return Commands.values();
	}
}